package com.springcloud.common.web.util;


/**
 * @author mori
 */
public abstract class AbstractUserContextHolder<T> {

    private ThreadLocal<T> threadLocal;

    public AbstractUserContextHolder() {
        this.threadLocal = new ThreadLocal<>();
    }

    /**
     * 用户上下文中放入信息
     *
     * @param t
     */
    public void setContext(T  t) {
        threadLocal.set(t);
    }

    /**
     * 获取上下文中的信息
     *
     * @return
     */
    public T getContext() {
        return threadLocal.get();
    }

    /**
     * 清空上下文
     */
    public void clear() {
        threadLocal.remove();
    }

}
